package com.cy.ppj.web.admin.product;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.cy.ppj.model.PageBean;
import com.cy.ppj.model.Result;
import com.cy.ppj.model.enums.RecommendType;
import com.cy.ppj.model.query.ProductRecommendAdminQuery;
import com.cy.ppj.model.query.RecommendedProductsAdminQuery;
import com.cy.ppj.model.vo.ProductRecommendAdminVO;
import com.cy.ppj.model.vo.RecommendedProductsAdminVO;
import com.cy.ppj.service.product.ProductService;
import com.cy.ppj.web.BaseController;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;

/**
 * 产品推荐管理
 * @author: tanyilin
 * @create: 2018年7月30日 下午7:45:07
 */
@Slf4j
@RestController
@RequestMapping("/admin/product/recommend")
@Api(tags = "后台-产品推荐管理")
public class AdminProductRecommendController extends BaseController{

	@Autowired
	private ProductService productService;
	
	@ApiOperation("产品推荐列表")
	@GetMapping("/list")
	public PageBean<ProductRecommendAdminVO> list(ProductRecommendAdminQuery productRecommendAdminQuery) {
		return productService.queryProductRecommendAdminList(productRecommendAdminQuery);
	}
	
	@ApiOperation("获取可推荐的产品列表")
	@GetMapping("/get/recommended/list")
	public PageBean<RecommendedProductsAdminVO> getRecommendedList(RecommendedProductsAdminQuery query) {
		PageBean<RecommendedProductsAdminVO> pageBean = productService.selectRecommendedProductsAdminList(query);
		return pageBean;
	}
	
	
	@ApiOperation("新增产品推荐位")
	@PostMapping("/add")
	public Result add(@ApiParam(value = "产品id", example = "0", required = true) @RequestParam Long productId,
			@ApiParam(value = "推荐类型", required = true) @RequestParam RecommendType type) {
		productService.addProductRecommend(productId, type);
		return ok();
	}
	
	@ApiOperation("删除推荐位")
	@PostMapping("/do/delete")
	public Result delete(@ApiParam(value = "推荐位id", example = "0", required = true) @RequestParam Long id) {
		productService.deleteProductRecommendById(id);
		return ok();
	}
}
